/*
获取所有x.parentId===parentId的项目，作为数组返回
*/
function levelOptionFilter(parentId,options) {
  if (options===null)  return []
  let res= options.filter(function(x) {
          return x.parentId ===parentId;
          }
        )

        return res
 }

function getLevelFromParentId(parentId,levelList){

  let res=levelOptionFilter(parentId,levelList)
 
  let options=[]
  if (res.length===0) return null
  

  for (let i = 0; i < res.length; i++) {
              
    let childOptions=getLevelFromParentId(res[i].id,levelList)
      if (childOptions!=null){
        options.push({label: res[i].name, value: res[i].id,disabled: false,children:childOptions});
      }else{
        options.push({label: res[i].name, value: res[i].id,disabled: false});
      }

  }
  
  return options

}
function getLevelLeave(levelList){
 
  let leaveOptions=[]
  for (let i = 0; i < levelList.length; i++) {
      let childOptions=getLevelFromParentId(levelList[i].id,levelList)
      
      if (childOptions===null){
          leaveOptions.push({label: levelList[i].name, value: levelList[i].id});
      }

  }

 
  return leaveOptions
}

const getters = {
  IMG_URL: state=>"https://localhost:7890/img/",
  sidebar: state => state.app.sidebar,
  device: state => state.app.device,
  token: state => state.user.token,
  avatar: state => state.user.avatar,
  name: state => state.user.name,
  userid: state => state.user.userid,
  role: state => state.user.role,
  addRouters: state => state.permission.addRouters,
  routers: state => state.permission.routers,

  subjectOptions: state => state.questiondata.subjectOptions,
  allTypeOptions: state => state.questiondata.allTypeOptions,
  

  verifyStatusOptions: state => state.questiondata.verifyStatusOptions,

  allLevelList: state => state.questiondata.allLevelList,
  
  levelOptions: state => {
    return getLevelFromParentId(0,state.questiondata.allLevelList)
  },
  leaveLevelOptions: state=>{
    return getLevelLeave(state.questiondata.allLevelList)
  },
  validStatusOptions: state => state.questiondata.validStatusOptions,
  testStatusOptions: state => state.questiondata.testStatusOptions,

  
  difStatusOptions: state => state.questiondata.difStatusOptions,
  starStatusOptions: state => state.questiondata.starStatusOptions,

  examStatusOptions: state => state.examdata.examStatusOptions,


}
export default getters
